package com.namo.cchfile.util;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author WangXin
 * @date 2021/3/31 10:58
 */
public class FileUtil {
    /**
     *获取文件content-type
     * @param filePath
     * @return
     * @throws IOException
     */
    public static String  getContentType(String filePath) throws IOException {
        String contentType = null;
        contentType =   Files.probeContentType(Paths.get(filePath));
        if (contentType == "" || contentType == null){
            contentType="application/octet-stream";
        }
        return  contentType;
    }

    /**
     *获取文件content-type
     * @param file
     * @return
     * @throws IOException
     */
    public static  String getContentType(File file) throws IOException {
        return getContentType(file.getPath());
    }
}
